import request from '@/utils/request'
import { getToken } from '@/utils/auth'
// 登录方法
export async function login(username, password, code, uuid) {
  const data = {username,password,code,uuid}
  /*
  return request({
    url: '/login',
    headers: {
      isToken: false,
      repeatSubmit: false
    },
    method: 'post',
    data: data
  })
  */
  return await fetch('https://vue.ruoyi.vip/prod-api/login', {
    method: 'POST', // *GET, POST, PUT, DELETE, etc.
    mode: 'cors', // no-cors, *cors, same-origin
    cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
    credentials: 'same-origin', // include, *same-origin, omit
    headers: {
      'Content-Type': 'application/json',
      'Host': 'vue.ruoyi.vip'      
    },
    body: JSON.stringify(data)
  }).then(res => res.json());
}

// 注册方法
export function register(data) {
  return request({
    url: '/register',
    headers: {
      isToken: false
    },
    method: 'post',
    data: data
  })
}

// 获取用户详细信息
export async function getInfo() {
  /*
  return request({
    url: '/getInfo',
    method: 'get'
  })
  */
 const token = getToken();
 return await fetch('https://vue.ruoyi.vip/prod-api/getInfo',{
    headers: new Headers({
      'Host': 'vue.ruoyi.vip',
      "authorization": "Bearer " + token
    })
  }).then(res => res.json())
}

// 退出方法
export async function logout() {
  /*
  return request({
    url: '/logout',
    method: 'post'
  })
  */
  return await fetch('https://vue.ruoyi.vip/prod-api/logout', {
    method: 'POST', // *GET, POST, PUT, DELETE, etc.
    mode: 'cors', // no-cors, *cors, same-origin
    cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
    credentials: 'same-origin', // include, *same-origin, omit
    headers: {
      'Content-Type': 'application/json',
      'Host': 'vue.ruoyi.vip'      
    },    
  }).then(res => res.json());
  
}

// 获取验证码
export async function getCodeImg() {
  /*
  return request({
    url: '/captchaImage',
    headers: {
      isToken: false,
      Host: 'vue.ruoyi.vip'
    },
    method: 'get',
    timeout: 20000
  })
  */
  return await fetch('https://vue.ruoyi.vip/prod-api/captchaImage', {
    headers: new Headers({
      'Host': 'vue.ruoyi.vip'
    })
  }).then(res => res.json());
  
}